<?php

class Authentication_Credentials_Local_Exception extends Authentication_Credentials_Exception {}
class Authentication_Credentials_Local_Invalid_Exception extends Authentication_Credentials_Local_Exception {}

class Authentication_Credentials_Local extends Authentication_Credentials {

	public function authenticate($credentials){
		if(!isset($credentials['username']) || !isset($credentials['password'])){
			throw new Authentication_Credentials_Local_Invalid_Exception($credentials);
		}
		$result = Database::getInstance()->query("SELECT * from `local_authentication` WHERE `username` = %s AND `password` = %s AND `site` = %s", $credentials['username'], md5($credentials['password']), Site::getInstance()->GetID());
		if(!($data = $result->fetch_assoc())){
			throw new Content_Not_Found_Exception();
		}

		return User::GetByID($data['user']);		

	}


}
